package com.example.materialviewpagerdemo;

import android.app.AlertDialog;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.materialviewpagerdemo.bean.ManualMoudel;
import com.example.materialviewpagerdemo.util.FyyDialog;
import com.example.materialviewpagerdemo.util.Sendcommand;
import com.github.florent37.materialviewpager.header.MaterialViewPagerHeaderDecorator;
import com.zyao89.view.zloading.ZLoadingDialog;

import java.util.ArrayList;
import java.util.List;


public class ManualFragment extends Fragment{
    public static Fragment newInstance(){return  new ManualFragment();}
    final List<ManualMoudel> items = new ArrayList<>();

    private ZLoadingDialog dialog;
    RecyclerView mRecyclerView;
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_recyclerview, container, false);
    }
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mRecyclerView=view.findViewById(R.id.recyclerView);
        dialog = new ZLoadingDialog(ManualFragment.this.getActivity());

        //指令采集moudle添加
        //->是lambda表达式，用于简化书写
        items.add(new ManualMoudel(R.drawable.ic_collect, "信息采集",v -> {
            String command = null;
            command = "BB00vtuceshi002EF";
            new Thread(new Sendcommand(command)).start();
            Toast.makeText(ManualFragment.this.getActivity(),"指令发送成功!",Toast.LENGTH_LONG).show();

        }));

        //水肥灌溉，硬件功能还没有
        items.add(new ManualMoudel(R.drawable.guangai, "水肥灌溉", v -> {
            AlertDialog.Builder builder=new AlertDialog.Builder(ManualFragment.this.getActivity(),R.style.Theme_AppCompat_Light_Dialog_Alert);
            builder.setTitle("提示").setMessage("硬件设施尚未安装，暂未开放")
                    .setPositiveButton("我知道了",null).setCancelable(true).create().show();
        }));

        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        mRecyclerView.setHasFixedSize(true);
        mRecyclerView.addItemDecoration(new MaterialViewPagerHeaderDecorator());
        mRecyclerView.setAdapter(new ManualAdapter(this.getActivity(),items));

    }
}
